package com.collect.cameroon.zhiScene.zhiWidget.zhiDialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.collect.cameroon.R;
import com.collect.cameroon.zhiAdater.zhiLevelDetail.ZHILevelDetailCollecterMemberB2;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCollecterPerformanceEntity;
import com.collect.cameroon.zhiScene.zhiWidget.zhiStepView.ZHINextStepView;
import com.collect.cameroon.zhiUtils.StringUtil;

import java.util.ArrayList;

public class ZHIDialogCollectMemberB2Performance extends Dialog {

    private TextView tv_title;
    private String mTitle;

    private final Context context;
    private final ZHILevelDetailCollecterMemberB2 mZHILevelDetailCollecterMemberB2 = new ZHILevelDetailCollecterMemberB2();

    public ZHIDialogCollectMemberB2Performance(Context context) {
        super(context, R.style.CustomDialog);
        this.context = context;
    }

    public static ZHIDialogCollectMemberB2Performance showDataSource(Context context1, String userName, ArrayList<ZHIRCollecterPerformanceEntity> arrayList){
        ZHIDialogCollectMemberB2Performance zhiDialogCollectMemberB2Performance = new ZHIDialogCollectMemberB2Performance(context1);
        zhiDialogCollectMemberB2Performance.showData(userName, arrayList);
        return zhiDialogCollectMemberB2Performance;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_collect_performance_member_b2);
        setCanceledOnTouchOutside(true);
        initView();
        refreshViewData();
        initViewEvent();
    }

    @Override
    public void show() {
        super.show();
        refreshViewData();
    }

    private void initView() {
        try {
            ZHINextStepView btn_close = findViewById(R.id.btn_close);
            btn_close.setOnMenuItemDidChangedListener(item -> dismiss());

            tv_title = findViewById(R.id.tv_title);

            RecyclerView rc_list = findViewById(R.id.rc_detail_list);
            rc_list.setLayoutManager(new GridLayoutManager(context, 1));
            rc_list.setAdapter(mZHILevelDetailCollecterMemberB2);

//            mZHILevelDetailCollecterMemberB2.setColumnItemClick(item -> ZHIDialogCustomerPerformanceAdminBonusV2.showDataSource(context, "Details", item.getBonusFormat(), item.getPenaltyFormat(), item.getActualBonusFormat()));

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void showData(String userName, ArrayList<ZHIRCollecterPerformanceEntity> arrayList) {
        mTitle = StringUtil.safeString(userName);
        mZHILevelDetailCollecterMemberB2.setNewData(arrayList);
        show();
    }

    private void refreshViewData() {
        tv_title.setText(mTitle);
    }

    private void initViewEvent() {


    }
}
